package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.OmcMerchandiseMapper;
import com.csun.cmny.provider.model.domain.OmcMerchandise;
import com.csun.cmny.provider.model.dto.longRangeServiceOrder.LongRangeSuperviseAnOrderMerchandiseDto;
import com.csun.cmny.provider.model.dto.merchandise.MerchandiseQueryDto;
import com.csun.cmny.provider.model.dto.merchandise.MerchandiseselectDto;
import com.csun.cmny.provider.model.vo.MerchandiseDetailVo;
import com.csun.cmny.provider.model.vo.MerchandiseVo;
import com.csun.cmny.provider.service.OmcMerchandiseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class OmcMerchandiseServiceImpl extends BaseService<OmcMerchandise>  implements OmcMerchandiseService {
    @Resource
    private OmcMerchandiseMapper merchandiseMapper;

    @Override
    public List<MerchandiseVo> selectMerchandise(MerchandiseQueryDto merchandiseQueryDto) {
        return merchandiseMapper.selectMerchandise(merchandiseQueryDto);
    }

    @Override
    public List<MerchandiseVo> selectByIdList(List<Long> idList) {
        return merchandiseMapper.selectByIdList(idList);
    }

    @Override
    public List<MerchandiseVo> selectMerchandiseAndmerchant(MerchandiseselectDto merchandiseselectDto) {
        return merchandiseMapper.selectMerchandiseAndmerchant(merchandiseselectDto);
    }

    @Override
    public List<MerchandiseDetailVo> selectBySecondId(Long secondLevelId) {
        return merchandiseMapper.selectBySecondId(secondLevelId);
    }

    @Override
    public int addSupervise(LongRangeSuperviseAnOrderMerchandiseDto longRangeSuperviseAnOrderMerchandiseDto, LoginAuthDto loginAuthDto) {
        OmcMerchandise merchandise = new OmcMerchandise();

        BeanUtils.copyProperties(longRangeSuperviseAnOrderMerchandiseDto,merchandise);

        merchandise.setUserId(loginAuthDto.getUserId());
        merchandise.setGroupId(loginAuthDto.getGroupId());
        merchandise.setOperator(loginAuthDto.getUserName());

        int save = save(merchandise);

        return save;
    }
}
